# 视图函数
from django.shortcuts import render
from django.views import View

def index(request):
    # print(request.method,'请求对象')
    # print(request.session)
    # print(request.headers)
    # print(dir(request))
    # print(request.COOKIES,request.FILES)
    # print(request.GET, request.POST)
    context={"page_title":"网站首页"}
    return render(request, 'index.html',context)

# def login(request):
#     # username = request.GET.get('username')
#     # password = request.GET.get('password')
#     # print(username,password)
#     if request.method=='POST':
#         username=request.POST.get('username')
#         password = request.POST.get('password')
#         print(username,password)
#     # 必须return render函数的执行结果
#     return render(request,'login.html')

class Login(View):
    # get请求
    def get(self,request):
        context={'page_title':'会员登录'}
        return render(request,'login.html',context)
    # post请求
    @staticmethod
    def post(request):
        username = request.POST.get('username')
        password = request.POST.get('password')
        print(username, password)
        context = {'page_title': '会员登录'}
        return render(request,'login.html',context)

class Reg(View):
    # 模板文件名称
    # template_name = 'reg.html'
    # 指定传递给模板文件的数据对象名称
    # context_objets_name={"page_title":"账号注册"}

    def get(self,request):
        context={
            "page_title":"会员注册"
        }
        return render(request,'reg.html',context)

    def post(self,request):
        username = request.POST.get('username')
        password = request.POST.get('password')
        print(username,password)
        context = {
            "page_title": "会员注册"
        }
        if not username and not password:
            context['error_msg']="请输入账号和密码"
            return  render(request,'reg.html',context)
        if username!='jack' and password!='123123':
            context['error_msg'] = "账号或者密码错误"
            return render(request, 'reg.html', context)
        context['success_msg']='注册成功'
        return render(request,'reg.html',context)


class Ucenter(View):
    def get(self,request):
        context={}
        return render(request,'ucenter.html',context)

    def post(self,request):
        context={}
        return render(request,'ucenter.html',context)



class GoodsList(View):
    def get(self,request):
        context={}
        return render(request,'goods_list.html',context)

    def post(self,request):
        context={}
        return render(request,'goods_list.html',context)


class Cart(View):
    def get(self,request):
        context={}
        return render(request,'cart.html',context)

    def post(self,request):
        context={}
        return render(request,'cart.html',context)

class OrderList(View):
    def get(self,request):
        context={}
        return render(request,'order_list.html',context)

    def post(self,request):
        context={}
        return render(request,'order_list.html',context)

class AddressList(View):
    def get(self,request):
        context={}
        return render(request,'address_list.html',context)

    def post(self,request):
        context={}
        return render(request,'address_list.html',context)

class Collects(View):
    def get(self,request):
        context={}
        return render(request,'collects.html',context)

    def post(self,request):
        context={}
        return render(request,'collects.html',context)


class Profile(View):
    def get(self,request):
        context={}
        return render(request,'profile.html',context)

    def post(self,request):
        context={}
        return render(request,'profile.html',context)

class ResetPwd(View):
    def get(self,request):
        context={}
        return render(request,'reset_pwd.html',context)

    def post(self,request):
        context={}
        return render(request,'reset_pwd.html',context)

class Goods(View):
    def get(self,request):
        context={}
        return render(request,'goods.html',context)

    def post(self,request):
        context={}
        return render(request,'goods.html',context)



